package com.zhangxin.aiInterview.manager.work_flow.ai_hr_interviewer.api;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.zhangxin.aiInterview.manager.work_flow.ai_hr_interviewer.constants.CozeConstants;
import org.springframework.stereotype.Service;


/**
 * 清除 Coze 会话上下文
 */
@Service
public class ClearHrConversationContext {

    /**
     * 清除指定会话的上下文
     * @param conversationId 会话ID
     * @return true：清除成功，false：失败
     */
    public boolean clear(String conversationId) {
        String url = "https://api.coze.cn/v1/conversations/" + conversationId + "/clear";

        HttpResponse response = HttpRequest.post(url)
            .header("Authorization", CozeConstants.TOKEN)
            .header("Content-Type", "application/json")
            .body("{}")
            .execute();

        JSONObject result = JSONUtil.parseObj(response.body());
        return result.getInt("code", -1) == 0;
    }
}